package ru.spb.nicetu.schoolproject.gui;

import ru.spb.nicetu.schoolproject.data.Pupil;
import ru.spb.nicetu.schoolproject.data.SchoolClass;

import javax.swing.*;
import java.awt.*;

/**
 * Created by dchernyshov on 11.04.15.
 */
public class PupilCard extends CardTemplate<Pupil, SchoolClass> {
    public PupilCard() {
        super(SchoolClass.class, "Карточка ученика", false, new Pupil());
        Box vbox = createVerticalBox();
        add(vbox, BorderLayout.CENTER);
    }

    public PupilCard(Pupil pupil) {
        super(SchoolClass.class, "Карточка ученика", true, pupil);
        Box vbox = createVerticalBox();
        add(vbox, BorderLayout.CENTER);
        lessonNumField.setText(pupil.getPupilName().trim());
        comboBox.setSelectedItem(pupil.getClazz());
    }

    @Override
    public void inputValue(Pupil object) {
        object.setPupilName(lessonNumField.getText().trim());
        object.setClazz((SchoolClass)comboBox.getSelectedItem());
    }

    @Override
    public boolean checkCard() {
        if (lessonNumField.getText().isEmpty()) {
            errorDialog("Введите ФИО!");
            return false;
        }
        return true;
    }

    public Box createVerticalBox() {
        Box box = Box.createVerticalBox();
        Box hbox1 = createFirstHorizontalBox("ФИО:");
        box.add(hbox1);
        box.add(Box.createVerticalStrut(10));
        Box hbox2 = createSecondHorizontalBox("Классы:");
        box.add(hbox2);
        box.add(Box.createHorizontalStrut(10));
        box.add(createLastHorizontalBox());
        box.add(Box.createVerticalGlue());
        return box;
    }
}
